package com.sikao.app.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.bean.EntrustListBean;
import com.sikao.app.utils.TimeUtil;

import java.util.List;

/**
 * Created by y50 on 2016/5/16.
 */
public class EntrustsAdapter extends BaseAdapter {

	private Context context;
	private List<EntrustListBean.ResBean.ListBean> beans;

	public EntrustsAdapter(Context context, List<EntrustListBean.ResBean.ListBean> beans) {
		this.context = context;
		this.beans = beans;
	}

	@Override
	public int getCount() {
		return beans.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view;
		ViewHolder holder;
		if (convertView == null) {
			view = View.inflate(context, R.layout.entrusts_list_item, null);
			holder = new ViewHolder(view);
			view.setTag(holder);
		} else {
			view = convertView;
			holder = (ViewHolder) view.getTag();
		}
		holder.tvEntrustTitle.setText(beans.get(position).getName());
		holder.tvContent.setText(beans.get(position).getCont());
		holder.tvTime.setText(TimeUtil.timeStampToTime(beans.get(position).getAdd_time(),TimeUtil.fotmatString2));
		holder.tvEntrustType.setText(beans.get(position).getType());
		return view;
	}

	public class ViewHolder {
		public final TextView tvEntrustTitle;
		public final TextView tvEntrustType;
		public final TextView tvContent;
		public final TextView tvTime;
		public final View root;

		public ViewHolder(View root) {
			tvEntrustTitle = (TextView) root.findViewById(R.id.tv_entrust_title);
			tvEntrustType = (TextView) root.findViewById(R.id.tv_entrust_type);
			tvContent = (TextView) root.findViewById(R.id.tv_content);
			tvTime = (TextView) root.findViewById(R.id.tv_time);
			this.root = root;
		}
	}
}
